package roborally;

import java.util.ArrayList;
import java.util.Iterator;
/**
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class BoardIterator implements Iterator<Element> {		 
		
		public BoardIterator(EnergyAtLeast test,Board board,double amount){
			for(Position position: board.getPositionMap().keySet()){
				for(Element elements:board.getPositionMap().get(position)){
					Element elementBack =  test.getElementBack(elements,amount);
					if (elementBack != null)
						iterArray.add(elementBack);		
				}
			}
		}

		@Override
		public boolean hasNext() {
			if (counter < iterArray.size()){
				return true;
			}
			return false;
		}

		@Override
		public Element next() {
			if (hasNext()){
				counter++;
				return iterArray.get(counter-1);
			}
			return null;
		}

		@Override
		public void remove() {
			if (counter>=1) {
				iterArray.remove(counter-1);
				counter--;
			}
		}
		
		private int counter=0;

		private ArrayList<Element> iterArray = new ArrayList<Element>();
	}